package p.ithorns.framework.core.model;

import lombok.Getter;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;

/**
 * ZipTreeNode
 *
 * @author HtL
 * @date 2024/6/21 19:28
 * @since 1.0.0
 */
@Getter
public class ZipTreeNode {

    // 文件名称
    private final String name;

    // zip条目
    private final ZipEntry entry;

    // 是否目录
    private final boolean isDirectory;

    // 子节点
    private final List<ZipTreeNode> children;

    // 完整路径
    private Path fullPath;

    public ZipTreeNode(String name, ZipEntry entry, boolean isDirectory) {
        this.name = name;
        this.entry = entry;
        this.isDirectory = isDirectory;
        this.children = new ArrayList<>();
    }

    public void setFullPath(Path fullPath) {
        this.fullPath = fullPath;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        ZipTreeNode treeNode = (ZipTreeNode) o;

        if (isDirectory != treeNode.isDirectory) {
            return false;
        }
        if (!name.equals(treeNode.name)) {
            return false;
        }
        return entry.equals(treeNode.entry);
    }

    @Override
    public int hashCode() {
        int result = name.hashCode();
        result = 31 * result + entry.hashCode();
        result = 31 * result + (isDirectory ? 1 : 0);
        return result;
    }

}